// Michael Depuy
// depuym@onid.orst.edu
// CS311-400
// Homework 1

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

void findPrimes(int numPrimes,int *primes){
  int i,j;

  for(i=0;i<numPrimes;i++){
    primes[i] = i;
  }

  primes[0] = -1;
  primes[1] = -1;
  
  for(i=2;i<numPrimes;i++){
    if(primes[i] != -1){
      for(j=i*i;j<numPrimes;j=j+i){
	primes[j] = -1;
      }
    }
  }
}

int main(int argc,char **argv){

  int limit = atoi(argv[1]);
  
  printf("Prime limit: %d\n",limit);

  int primes[limit];
  findPrimes(limit,primes);

  int primesCount = 0;
  int i;

  for(i=0;i<limit;i++){
    if(primes[i] != -1)
       primesCount += 1;
  }
  printf("Number of primes in your list: %d\n\n",primesCount);
  
  for(i=0;i<limit;i++){
    if(primes[i] != -1)
      printf("%d\t",primes[i]);
  }
  printf("\n");

  return 0;
}
